package br.com.notepadeti.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.com.notepadeti.controller.NotaBO;
import br.com.notepadeti.form.NotaForm;

public class NotaAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
        String target = null;
        NotaForm notaForm = (NotaForm)form; 
 
        if(!notaForm.getDescricao().equals("")) {
            target = "success";
            request.setAttribute("message", notaForm.getSenha());
        }
        else {
            target = "failure";
        }

        NotaBO nb = new NotaBO();
        nb.cadastrarNota(notaForm.getDescricao(), notaForm.getUrl(), notaForm.getSenha());
        
        return mapping.findForward(target);
	}
	
}
